/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Panel;

import DAO.*;
import OBJECT.DangKiVanChuyen;
import OBJECT.LichTrinh;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Date;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import util.Global;

/**
 *
 * @author Ngoc Anh
 */
public class DangKiVanChuyenForm extends javax.swing.JPanel {

    /**
     * Creates new form DangKiVanChuyenForm
     */
    public LichTrinh lichtrinh;
   DefaultTableModel tablemodelLichTrinh;
   DefaultTableModel tablemodelVanChuyen;
   LichTrinhDAO ltdao;
   ChiTietTuyenDuongDAO cttddao;
   DefaultComboBoxModel combox;
   DangKiVanChuyenDao dkvc ;
   QuyDinhDAO qd;
   String username;
   int Makh=Global.customer.getMaKh();
   String password;
   DangKiVanChuyen dk ;
    public DangKiVanChuyenForm(String User ,String Pass,String port,String DataBase,String Host,LichTrinh lt) {
        initComponents();
        lichtrinh=lt;
           tbLichTrinh.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
           jTableDKVC.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            tablemodelLichTrinh = new DefaultTableModel();
            tablemodelVanChuyen = new DefaultTableModel();            
            combox = new DefaultComboBoxModel();
            
        tablemodelLichTrinh.addColumn("Mã Lt");
        tablemodelLichTrinh.addColumn("Mã Tuyến Đường");
        tablemodelLichTrinh.addColumn("Mã Tàu");
        tablemodelLichTrinh.addColumn("Thời Gian Khởi Hành");
        tablemodelLichTrinh.addColumn("Thời Gian Đến");
        tablemodelLichTrinh.addColumn("Số Contenter Còn Trống");
        tablemodelLichTrinh.addColumn("Tình Trạng");
        tbLichTrinh.setModel(tablemodelLichTrinh);
        
        tablemodelVanChuyen.addColumn("Khach Hang");
        tablemodelVanChuyen.addColumn("Ma Van Chuyen");
        tablemodelVanChuyen.addColumn("Ten Ga Den");
        tablemodelVanChuyen.addColumn("SoContainer");
        tablemodelVanChuyen.addColumn("Tong Tien");
        tablemodelVanChuyen.addColumn("Tinh Trang Dk");
        tablemodelVanChuyen.addColumn("Ngay Dang Ky");
        tablemodelVanChuyen.addColumn("Ma DK");
        jTableDKVC.setModel(tablemodelVanChuyen);
        
        ltdao =new LichTrinhDAO(User , Pass, port, DataBase, Host);
        cttddao = new ChiTietTuyenDuongDAO(User , Pass, port, DataBase, Host);
        qd = new QuyDinhDAO(User , Pass, port, DataBase, Host);
        dkvc = new DangKiVanChuyenDao(User , Pass, port, DataBase, Host);
        jTextFieldSoLuong.setVisible(false);
        jTextGaDen.setVisible(false);
        this.jButtonUpdate.setVisible(false);
        this.jButtonDelete.setVisible(false);
        showList();// show danh sach lich trinh
        showListDKVC(); // show danh sach dang ki cua khach hang
        
    }
    
      private void showList()
        {
            
                        if(lichtrinh==null)
                        {
                        String Soluong="";
                        CallableStatement cls=ltdao.DanhSachLichTrinh();
                        try
                        {
                            cls.registerOutParameter(1, java.sql.Types.INTEGER);                   
                            cls.execute();
                            ResultSet result=cls.getResultSet(); 
                        while(result.next())
                            {
                                if(result.getString("TinhTrang").equals("2")==false)
                                {
                                    Vector vt = new Vector();
                                    vt.add(result.getInt("Ma_LichTrinhVC"));
                                    vt.add(result.getInt("Ma_TuyenDuong"));
                                    vt.add(result.getInt("Ma_Tau"));
                                    Date d=result.getDate("ThoiGianKhoiHanh");
                                    vt.add(d.getDate()+"-"+(int)(d.getMonth()+1)+"-"+(int)(d.getYear()+1900));
                                    Date d1=result.getDate("ThoiGianDen");
                                    vt.add(d1.getDate()+"-"+(int)(d.getMonth()+1)+"-"+(int)(d.getYear()+1900));
                                    vt.add(result.getInt("SoContainerConTrong"));
                                    vt.add(result.getString("TinhTrang"));
                                    tablemodelLichTrinh.addRow(vt);
                                }
                            }
                        result.close();
                            Soluong=""+cls.getInt(1);
                            cls.close();
                            ltdao.CloseConnect();
                        }catch(Exception e)
                        {
                            ;
                        }
                        }
                        else
                        {
                             Vector vt = new Vector();
                                    vt.add(lichtrinh.getMaLichTrinh());
                                    vt.add(lichtrinh.getMaTuyenDuong());
                                    vt.add(lichtrinh.getMaTau());
                                    Date d=lichtrinh.getTGKhoiHanh();
                                    vt.add(d.getDate()+"-"+(int)(d.getMonth()+1)+"-"+(int)(d.getYear()+1900));
                                    Date d1=lichtrinh.getTGDen();
                                    vt.add(d1.getDate()+"-"+(int)(d.getMonth()+1)+"-"+(int)(d.getYear()+1900));
                                    vt.add(lichtrinh.getContent());
                                    vt.add(lichtrinh.getTinhTrang());
                                    tablemodelLichTrinh.addRow(vt);
                        }
                       // lbSoLuong.setText(Soluong);
        }

      private void showListDKVC()
      {
          
          try{
                CallableStatement cls =  dkvc.DanhSachDangKiVanChuyen1KH(Makh);
               // cls.registerOutParameter(1, java.sql.Types.INTEGER);                   
                cls.execute();
                ResultSet result=cls.getResultSet(); 
                while(result.next())
                {
                    Vector vt = new Vector();                    
                    vt.add(result.getInt("Ma_KH"));
                    vt.add(result.getInt("Ma_VanChuyen"));
                    vt.add(result.getString("TenGaDen"));
                    vt.add(result.getInt("SoCotainer"));
                    vt.add(result.getFloat("TongTien"));
                    vt.add(result.getString("TinhTrangDK"));
                    vt.add(result.getDate("NgayDK"));
                    vt.add(result.getInt("Ma_DKi"));
                    tablemodelVanChuyen.addRow(vt);
                }
              result.close();
              cls.close();
              dkvc.CloseConnect();
          }catch(Exception exc)
          {
               System.out.println(exc);
          }
      }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelDanhSachLichTrinh = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBoxGaDen = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldSoLuong = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabelThanTieh = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jButtonInsert = new javax.swing.JButton();
        jButtonUpdate = new javax.swing.JButton();
        jButtonDelete = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextGaDen = new javax.swing.JTextField();
        jLabelThanhTien = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabelSoKm = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableDKVC = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbLichTrinh = new javax.swing.JTable();

        jPanelDanhSachLichTrinh.setBackground(new java.awt.Color(204, 204, 255));
        jPanelDanhSachLichTrinh.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanelDanhSachLichTrinh.setForeground(new java.awt.Color(0, 0, 255));
        jPanelDanhSachLichTrinh.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Nyala", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 102, 102));
        jLabel1.setText("Danh Sach Cac Ga den");

        jComboBoxGaDen.setBackground(new java.awt.Color(0, 153, 153));
        jComboBoxGaDen.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jComboBoxGaDen.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBoxGaDenMouseClicked(evt);
            }
        });
        jComboBoxGaDen.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxGaDenItemStateChanged(evt);
            }
        });
        jComboBoxGaDen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxGaDenActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(0, 102, 102));
        jLabel2.setText("So Container");

        jLabel3.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(0, 102, 102));
        jLabel3.setText("Thanh tien");

        jPanel1.setBackground(new java.awt.Color(0, 153, 153));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thao tac", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Bodoni MT", 1, 18), java.awt.Color.orange)); // NOI18N

        jButtonInsert.setText("Insert");
        jButtonInsert.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonInsertMouseClicked(evt);
            }
        });
        jButtonInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonInsertActionPerformed(evt);
            }
        });

        jButtonUpdate.setText("Update");
        jButtonUpdate.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonUpdateMouseClicked(evt);
            }
        });
        jButtonUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonUpdateActionPerformed(evt);
            }
        });

        jButtonDelete.setText("Delete");
        jButtonDelete.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonDeleteMouseClicked(evt);
            }
        });
        jButtonDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonDelete)
                    .addComponent(jButtonUpdate)
                    .addComponent(jButtonInsert))
                .addGap(0, 17, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonInsert)
                .addGap(18, 18, 18)
                .addComponent(jButtonUpdate)
                .addGap(18, 18, 18)
                .addComponent(jButtonDelete)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel4.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(0, 102, 102));
        jLabel4.setText("Ten Ga Den");

        jLabelThanhTien.setText("0");

        jLabel5.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(0, 102, 102));
        jLabel5.setText("So Km");

        jLabelSoKm.setText("0");

        jPanel2.setBackground(new java.awt.Color(0, 153, 153));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh Sach Dang Ky Van Chuyen Cua Khach Hang", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Bodoni MT", 1, 18), java.awt.Color.orange)); // NOI18N
        jPanel2.setForeground(new java.awt.Color(0, 51, 255));
        jPanel2.setAlignmentY(1.0F);

        jTableDKVC.setBackground(new java.awt.Color(204, 204, 204));
        jTableDKVC.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTableDKVC.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableDKVC.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTableDKVCMousePressed(evt);
            }
        });
        jScrollPane2.setViewportView(jTableDKVC);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(0, 153, 153));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh Sach Lich Trinh Van Chuyen", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Bodoni MT", 1, 18), java.awt.Color.orange)); // NOI18N
        jPanel3.setForeground(new java.awt.Color(204, 51, 0));

        tbLichTrinh.setBackground(new java.awt.Color(204, 204, 204));
        tbLichTrinh.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        tbLichTrinh.setForeground(new java.awt.Color(0, 153, 153));
        tbLichTrinh.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbLichTrinh.setCellSelectionEnabled(true);
        tbLichTrinh.setSelectionBackground(new java.awt.Color(255, 255, 255));
        tbLichTrinh.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbLichTrinhMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbLichTrinhMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(tbLichTrinh);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanelDanhSachLichTrinhLayout = new javax.swing.GroupLayout(jPanelDanhSachLichTrinh);
        jPanelDanhSachLichTrinh.setLayout(jPanelDanhSachLichTrinhLayout);
        jPanelDanhSachLichTrinhLayout.setHorizontalGroup(
            jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                                .addGap(319, 319, 319)
                                .addComponent(jLabelThanTieh, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addGap(63, 63, 63))
                                    .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(18, 18, 18)))
                                .addGap(10, 10, 10)
                                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jTextGaDen, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelSoKm, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelThanhTien, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                        .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxGaDen, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelDanhSachLichTrinhLayout.setVerticalGroup(
            jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBoxGaDen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(154, 154, 154))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)))
                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                                .addGap(124, 124, 124)
                                .addComponent(jLabelThanTieh))
                            .addGroup(jPanelDanhSachLichTrinhLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabelSoKm))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextGaDen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelDanhSachLichTrinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabelThanhTien)))))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelDanhSachLichTrinh, javax.swing.GroupLayout.PREFERRED_SIZE, 857, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelDanhSachLichTrinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

  //  List<ChiTietTuyenDuong> listcttd = new ArrayList<ChiTietTuyenDuong>();  
    private void tbLichTrinhMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbLichTrinhMousePressed
//        // TODO add your handling code here:
       // System.out.println("malt"+lichtrinh.getMaLichTrinh());
        jTextFieldSoLuong.setVisible(true);
         jTextGaDen.setVisible(true);
         int row = this.tbLichTrinh.getSelectedRow();
        int giatri = Integer.parseInt(tbLichTrinh.getValueAt(row, 1).toString());   
        
        CallableStatement    listcttd  = cttddao.DanhSachGaCua1TuyenDuong(giatri);
        combox = (DefaultComboBoxModel)jComboBoxGaDen.getModel();
        combox.removeAllElements();
          try
            {
                listcttd.execute(); 
                ResultSet result= listcttd.getResultSet();
                
                 while(result.next())
                 {                     
                     Vector vt = new Vector();
                     vt.add(result.getInt("MaCT_TuyenDuong"));
                     vt.add(result.getString("TenGaDen"));                     
                     jLabelSoKm.setText(String.valueOf(result.getFloat("SoKM")));
                     jComboBoxGaDen.addItem(vt);                                         
                 }
                 result.close();  
                 listcttd.close();
                 cttddao.CloseConnect();
            }catch(Exception exc)
            {
                   System.out.println(exc);
            }
      
    }//GEN-LAST:event_tbLichTrinhMousePressed

    private void tbLichTrinhMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbLichTrinhMouseClicked
        // TODO add your handling code here:
         
          
    }//GEN-LAST:event_tbLichTrinhMouseClicked

 private void clearListLichTrinh()
{
   for(int i = tablemodelLichTrinh.getRowCount() -1;i >= 0;i--)
            tablemodelLichTrinh.removeRow(i);   
}
 
 private void clearListDangKi()
{
   for(int i = tablemodelVanChuyen.getRowCount() -1;i >= 0;i--)
           tablemodelVanChuyen.removeRow(i);
   
}
    
    private void jButtonInsertMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonInsertMouseClicked
        // TODO add your handling code here:        
                      
     
    }//GEN-LAST:event_jButtonInsertMouseClicked
    
    int containbefore ;
    private void jTableDKVCMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableDKVCMousePressed
        // TODO add your handling code here
        
         jTextFieldSoLuong.setVisible(true);
         jTextGaDen.setVisible(true);
         this.jButtonUpdate.setVisible(true);
         this.jButtonDelete.setVisible(true);
         
         dk   = new DangKiVanChuyen();      
         try{
            int row = this.jTableDKVC.getSelectedRow();       
            jTextGaDen.setText(jTableDKVC.getValueAt(row,2 ).toString());
            jTextFieldSoLuong.setText((jTableDKVC.getValueAt(row,3).toString()));
            
            dk.setMaDangKiVC(Integer.parseInt(jTableDKVC.getValueAt(row,7).toString()));
            dk.setMaKH(Integer.parseInt(jTableDKVC.getValueAt(row,0).toString()));
            dk.setMaVanChuyen(Integer.parseInt(jTableDKVC.getValueAt(row,1).toString()));    
            dk.setSoContainer(Integer.parseInt(jTextFieldSoLuong.getText()));
             
            dk.setTenGaDen( jTextGaDen.getText());  
            containbefore = Integer.parseInt(jTableDKVC.getValueAt(row,3).toString());
            
            
         }catch(Exception exc)
         {
            System.out.println("sac"+exc.getMessage()); 
         }
        
        
    }//GEN-LAST:event_jTableDKVCMousePressed

    private void jButtonUpdateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonUpdateMouseClicked
        // TODO add your handling code here:
       
    }//GEN-LAST:event_jButtonUpdateMouseClicked

    private void jButtonDeleteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonDeleteMouseClicked
        // TODO add your handling code here:
        int row = this.jTableDKVC.getSelectedRow(); 
        int madk = Integer.parseInt(jTableDKVC.getValueAt(row,7).toString());
        String huy = dkvc.HuyDangKiVanChuyen(madk);
       
             JOptionPane.showMessageDialog(this,huy,"OK",JOptionPane.INFORMATION_MESSAGE);
             clearListDangKi();
             showListDKVC();
        
    }//GEN-LAST:event_jButtonDeleteMouseClicked

    private void jComboBoxGaDenMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBoxGaDenMouseClicked
        // TODO add your handling code here:
       
    }//GEN-LAST:event_jComboBoxGaDenMouseClicked

    private void jComboBoxGaDenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxGaDenActionPerformed
        // TODO add your handling code here:
     //    jTextGaDen.setText(this.jComboBoxGaDen.getSelectedItem().toString());
    }//GEN-LAST:event_jComboBoxGaDenActionPerformed

                                             

                                                   


    private void jButtonInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonInsertActionPerformed
        // TODO add your handling code here:
         if(jTextFieldSoLuong.getText().equals("")) // Kiem tra So Luong Container bi trong
        {
            System.out.println("Phai nhap vao so container muon van chuyen");
            JOptionPane.showMessageDialog(this,"Phai nhap vao so container muon van chuyen","OK",JOptionPane.INFORMATION_MESSAGE);
            return;
        }
       
        int row = this.tbLichTrinh.getSelectedRow();
        int sl = Integer.parseInt(jTextFieldSoLuong.getText());
        if(sl > Integer.parseInt(tbLichTrinh.getValueAt(row,5 ).toString())) // Kiem tra Vuot qua so container con trong
        {
            System.out.println("Qua so luong container con trong");
            JOptionPane.showMessageDialog(this,"Qua so luong container con trong","OK",JOptionPane.INFORMATION_MESSAGE);
            return ;
        }
        try{
                CallableStatement cals = qd.ThongTinQuyDinh(); 
                ResultSet result=cals.executeQuery();
                float dongia = 0 ;
                    while(result.next())
                    {
                        dongia = result.getFloat("DonGia_VC_Contener_Km");
                    }
                    result.close();
                    cals.close();
                    qd.CloseConnect();
                    float thanhtien = (float) dongia * sl* Float.parseFloat(jLabelSoKm.getText());
                    jLabelThanhTien.setText(String.valueOf(thanhtien));
                    DangKiVanChuyen vc = new DangKiVanChuyen();
                   
                    vc.setMaKH(Makh);         
                    vc.setMaVanChuyen(Integer.parseInt(tbLichTrinh.getValueAt(row,0 ).toString()));
                    vc.setTenGaDen(this.jComboBoxGaDen.getSelectedItem().toString());
                    vc.setTongTien(thanhtien);
                    vc.setSoContainer(sl);
                    String kq =  dkvc.ThemDangKiVanChuyen(vc);
                    
                        JOptionPane.showMessageDialog(this, kq ,"OK",JOptionPane.INFORMATION_MESSAGE);
                       // tbLichTrinh.clearSelection();
                        clearListDangKi();
                        showListDKVC();
                        clearListLichTrinh();                        
                        showList(); 
        }catch(Exception exc)
        {
          ; 
        } 

    }//GEN-LAST:event_jButtonInsertActionPerformed

    private void jComboBoxGaDenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxGaDenItemStateChanged
        // TODO add your handling code here:
         if(jTextGaDen.equals(""))
        {
            JOptionPane.showMessageDialog(this,"Chua chon ga den","OK",JOptionPane.INFORMATION_MESSAGE);
            return ;
        }
       if(this.jComboBoxGaDen.getSelectedIndex()!=-1)
       jTextGaDen.setText(this.jComboBoxGaDen.getSelectedItem().toString());
    }//GEN-LAST:event_jComboBoxGaDenItemStateChanged

    private void jButtonUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUpdateActionPerformed
        // TODO add your handling code here:
         if(jTextGaDen.equals(""))
        {
            JOptionPane.showMessageDialog(this,"Chua chon ga den","OK",JOptionPane.INFORMATION_MESSAGE);
            return ;
        }
        try{
            CallableStatement cals = qd.ThongTinQuyDinh(); 
            
            float dongia = 0 ;
            ResultSet result=cals.executeQuery();
                while(result.next())
                {
                    dongia = result.getFloat("DonGia_VC_Contener_Km");
                }
                result.close();
               cals.close();
                qd.CloseConnect();
                float thanhtien = dongia * Integer.parseInt(jTextFieldSoLuong.getText());
               
                jLabelThanhTien.setText(String.valueOf(thanhtien));
                
                dk.setTongTien(thanhtien);
                dk.setTenGaDen(this.jTextGaDen.getText());
                dk.setSoContainer(Integer.parseInt(this.jTextFieldSoLuong.getText()));
                  
                String capnhat =  dkvc.SuaDangKyVanChuyen(dk);              
              
                    JOptionPane.showMessageDialog(this,capnhat,"OK",JOptionPane.INFORMATION_MESSAGE);
                    clearListDangKi();
                    showListDKVC();
                    
                    clearListLichTrinh();
                    showList();
               
        }catch(Exception exc)
        {
            System.out.println(exc.getMessage());
        }
    }//GEN-LAST:event_jButtonUpdateActionPerformed

    private void jButtonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonDeleteActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonDelete;
    private javax.swing.JButton jButtonInsert;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JComboBox jComboBoxGaDen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabelSoKm;
    private javax.swing.JLabel jLabelThanTieh;
    private javax.swing.JLabel jLabelThanhTien;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanelDanhSachLichTrinh;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTableDKVC;
    private javax.swing.JTextField jTextFieldSoLuong;
    private javax.swing.JTextField jTextGaDen;
    private javax.swing.JTable tbLichTrinh;
    // End of variables declaration//GEN-END:variables
}
